home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Beta / Quicktime 2.0 Beta.iso / Extensions / Color Picker 2.0 / ColorPicker.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-28  |  13.7 KB  |  511 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        ColorPicker.h
  3.  
  4.     Contains:    The public Color Picker Manager routines and data structures.
  5.  
  6.     Written by:    Shannon Holland
  7.  
  8.     Copyright:    © 1991-1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.         <66>      2/7/94    SAH        Moved typedef inside #ifndef to stop compile errors for people
  13.                                     who have included the old headers
  14.         <65>    11/15/93    SAH        Added a new __COLORPICKER__ define so that we don't re-include
  15.                                     ourselves. Also added more checks for __PICKER__ in case people
  16.                                     include us over the old header file.
  17.         <64>     11/8/93    SAH        Fixed header
  18.         <63>     11/8/93    SAH        Added gestalt selector.
  19.  
  20. */
  21.  
  22. #ifndef    __COLORPICKER__
  23. #define    __COLORPICKER__
  24.  
  25. #include <QuickDraw.h>
  26. #include <Events.h>
  27. #include <Balloons.h>
  28.  
  29. #ifndef ColorPicker
  30. #define    ColorPicker
  31.  
  32. #define        kDefaultWidth            383
  33. #define        kDefaultHeight            238
  34.  
  35. // our gestalt selector
  36. #define        gestaltColorPicker        'cpkr'
  37.  
  38.  
  39.     /* Data structures and flags */
  40.  
  41. #ifndef __CMAPPLICATION__
  42. #ifndef    CMApplication
  43.  
  44. /* define some colorsync types in case the caller didn't include them first */
  45.  
  46. typedef struct CMPRofile **CMProfileHandle;
  47.  
  48. typedef struct {
  49.     unsigned short        X;            /* these should be 1.15 fixed numbers */
  50.     unsigned short        Y;
  51.     unsigned short        Z;
  52. } XYZColor;
  53.  
  54. typedef struct {
  55.     unsigned short        c;            /* these should be 1.15 fixed numbers */
  56.     unsigned short        m;
  57.     unsigned short        y;
  58.     unsigned short        k;
  59. } CMYKColor;
  60.  
  61. typedef union {
  62.     RGBColor        rgb;
  63.     XYZColor        xyz;
  64.     CMYKColor    cmyk;
  65.     unsigned short    reserved[4];
  66. } CMColor, *CMColorList;
  67.  
  68. #endif
  69. #endif
  70.  
  71. typedef struct PMColor
  72. {
  73.     CMProfileHandle profile;
  74.     CMColor color;
  75. } PMColor,*PMColorPtr;
  76.  
  77. typedef struct PrivatePickerRecord **picker;
  78.  
  79. /*
  80. *    The actions returned to the application from DoPickerEvent
  81. */
  82. enum PickerAction
  83. {
  84.     kDidNothing,
  85.     kColorChanged,
  86.     kOkHit,
  87.     kCancelHit,
  88.     kNewPickerChosen,
  89.     kApplItemHit
  90. };
  91.  
  92. typedef short PickerAction;
  93.  
  94. /*
  95. *    The types of colors a picker must maintain
  96. */
  97. enum ColorTypes
  98. {
  99.     kOriginalColor,        // the original color passed to the picker manager
  100.     kNewColor            // the current color the user has chosen
  101. };
  102.  
  103. typedef short ColorType;
  104.  
  105. /*
  106. *    The types of edit operations that are sent with the kEdit message
  107. */
  108. enum EditOperations
  109. {
  110.     kCut,
  111.     kCopy,
  112.     kPaste,
  113.     kClear,
  114.     kUndo
  115. };
  116.  
  117. typedef short EditOperation;
  118.  
  119. /*
  120. *    The Item hit modifiers. These are sent along with the itemHit message and inform the picker
  121. *    of what it was that caused the item hit.
  122. */
  123. enum ItemHitModiefiers
  124. {
  125.     kMouseDown,            // mouseDown on item
  126.     kKeyDown,            // keydown in current edit item
  127.     kFieldEntered,        // tab into an edit field
  128.     kFieldLeft,            // tab out of an edit field
  129.     kCutOp,                // cut in current edit field
  130.     kCopyOp,            // copy in current edit field
  131.     kPasteOp,            // paste in current edit field
  132.     kClearOp,            // clear in current edit field
  133.     kUndoOp                // undo in current edit field
  134. };
  135.  
  136. typedef short ItemModifier;
  137.  
  138.  
  139. /*
  140. *    The dialog placement specifiers. These tell the picker manager where to place
  141. *    the picker dialog (used for system dialogs).
  142. */
  143.  
  144. enum DialogPlacementSpecifiers
  145. {
  146.     kAtSpecifiedOrigin,
  147.     kDeepestColorScreen,
  148.     kCenterOnMainScreen
  149. };
  150.  
  151. typedef short DialogPlacementSpec;
  152.  
  153.  
  154. /*
  155. *    Picker flags
  156. */
  157.  
  158. // these flags may be set by the app and are passed through to the picker
  159. #define        DialogIsMoveable        1        // the dialog can be moved
  160. #define        DialogIsModal            2        // the dialog is modal
  161. #define        CanModifyPalette        4        // the picker is allowed to install a palette
  162. #define        CanAnimatePalette        8        // the picker is allowed to animate the palette
  163. #define        AppIsColorSyncAware        16        // The application is ColorSync aware and can therfore
  164.                                             // convert colors between spaces (ie it can accept non-RGB
  165.                                             // colors)
  166.  
  167. // these flags are set by the picker manager (overriding any application settings)
  168. #define        InSystemDialog            32        // the picker is in a system dialog
  169. #define        InApplicationDialog        64        // the picker is in an application dialog
  170. #define        InPickerDialog            128        // the picker is in its own dialog
  171. #define        DetachedFromChoices        256        // the picker has been detached from the choices
  172.                                             // list
  173.  
  174.  
  175. /*
  176. *    Picker attributes (bits 23 to 0 in the componentFlags field of the component thng)
  177. */
  178.  
  179. #define        CanDoColor                1        // the picker can live in Color QD Environments
  180. #define        CanDoBlackWhite            2        // the picker can live in Classic QD Environments
  181. #define        AlwaysModifiesPalette    4        // the picker will modify palette entries on indexed
  182.                                             // devices
  183. #define        MayModifyPalette        8        // the picker will modify palette if told it can
  184. #define        PickerIsColorSyncAware    16        // the picker is ColorSync aware and can accept 
  185.                                             // non-RGB colors
  186. #define        CanDoSystemDialog        32        // the picker can live inside a system dialog
  187. #define        CanDoApplDialog            64        // the picker can live inside an application
  188. #define        HasOwnDialog            128        // the picker has its own dialog
  189. #define        CanDetach                256        // the picker can detach from a system dialog
  190.  
  191.  
  192. /*
  193. *    The extended picker data structure list-view information the component manager doesn't keep.
  194. *    around. This data is accessed via the kGetIconData message.
  195. */
  196.  
  197. typedef struct PickerIconData
  198. {
  199.     short scriptCode;
  200.     short iconSuiteID;
  201.     ResType helpResType;
  202.     short helpResID;
  203. } PickerIconData;
  204.  
  205. typedef struct PickerInitData
  206. {
  207.     DialogPtr pickerDialog;
  208.     DialogPtr choicesDialog;
  209.     long flags;
  210.     picker yourself;
  211. } PickerInitData;
  212.  
  213. /*
  214. *    Picker error messages
  215. */
  216.  
  217. enum
  218. {
  219.     firstPickerError = -4000,
  220.     
  221.     invalidPickerType = firstPickerError,
  222.     requiredFlagsDontMatch = -4001,
  223.     pickerResourceError = -4002,
  224.     cantLoadPicker = -4003,
  225.     cantCreatePickerWindow = -4004,
  226.     cantLoadPackage = -4005,
  227.     pickerCantLive = -4006,
  228.     colorSyncNotInstalled = -4007,
  229.     badProfileError = -4008,
  230.     noHelpForItem = -4009
  231. };
  232.     
  233. /*
  234. *    The application filter proc for DoPickerEvent
  235. */
  236.  
  237. typedef pascal Boolean (*UserEventProc)(EventRecord *event);
  238.  
  239. /*
  240. *    The application proc to be called when the color changes (called by the picker itself).
  241. */
  242.  
  243. typedef pascal void (*ColorChangedProc)(long userData,PMColorPtr newColor);
  244.  
  245. enum EventForcasters
  246. {
  247.     kNoForcast,            // no forcast (eg an update event)
  248.     kMenuChoice,        // this event will cause a menu to be chosen
  249.     kDialogAccept,        // the dialog will be accepted
  250.     kDialogCancel,        // the dialog will be cancelled
  251.     kLeaveFocus,        // the focus will leave the picker
  252.     kPickerSwitch,        // new picker chosen in more choices list
  253.     kNormalKeyDown,        // a normal key down to an edit field
  254.     kNormalMouseDown    // a normal click within the picker's focus
  255. };
  256.  
  257. typedef short EventForcaster;
  258.  
  259. // the structure that details the location of the edit menu and its items
  260. typedef struct MenuItemInfo
  261. {
  262.     short editMenuID;
  263.     short cutItem;
  264.     short copyItem;
  265.     short pasteItem;
  266.     short clearItem;
  267.     short undoItem;
  268. } MenuItemInfo;
  269.  
  270. // a structure which details the state the picker wishes the edit menu items to be in
  271. typedef struct MenuState
  272. {
  273.     Boolean cutEnabled;
  274.     Boolean copyEnabled;
  275.     Boolean pasteEnabled;
  276.     Boolean clearEnabled;
  277.     Boolean undoEnabled;
  278.     Str255 undoString;
  279. } MenuState;
  280.  
  281. typedef struct ColorPickerInfo
  282. {
  283.     PMColor theColor;
  284.     CMProfileHandle dstProfile;
  285.     long flags;
  286.     DialogPlacementSpec placeWhere;
  287.     Point dialogOrigin;
  288.     long pickerType;
  289.     UserEventProc eventProc;
  290.     ColorChangedProc colorProc;
  291.     long colorProcData;
  292.     Str255 prompt;
  293.     MenuItemInfo mInfo;
  294.     Boolean newColorChosen;
  295. } ColorPickerInfo;
  296.  
  297. typedef struct SystemDialogInfo
  298. {
  299.     long flags;
  300.     long pickerType;
  301.     DialogPlacementSpec placeWhere;
  302.     Point dialogOrigin;
  303.     MenuItemInfo mInfo;
  304. } SystemDialogInfo;
  305.  
  306. typedef struct PickerDialogInfo
  307. {
  308.     long flags;
  309.     long pickerType;
  310.     Point *dialogOrigin;
  311.     MenuItemInfo mInfo;
  312. } PickerDialogInfo;
  313.  
  314. typedef struct ApplicationDialogInfo
  315. {
  316.     long flags;
  317.     long pickerType;
  318.     DialogPtr theDialog;
  319.     Point pickerOrigin;
  320.     MenuItemInfo mInfo;
  321. } ApplicationDialogInfo;
  322.  
  323. typedef struct EventData
  324. {
  325.     EventRecord *event;
  326.     PickerAction action;
  327.     short itemHit;
  328.     Boolean handled;
  329.     ColorChangedProc colorProc;
  330.     long colorProcData;
  331.     EventForcaster forcast;
  332. } EventData;
  333.  
  334. typedef struct EditData
  335. {
  336.     EditOperation theEdit;
  337.     PickerAction action;
  338.     Boolean handled;
  339. } EditData;
  340.  
  341. typedef struct ItemHitData
  342. {
  343.     short itemHit;
  344.     ItemModifier iMod;
  345.     PickerAction action;
  346.     ColorChangedProc colorProc;
  347.     long colorProcData;
  348.     Point where;
  349. } ItemHitData;
  350.     
  351.  
  352. typedef struct HelpItemInfo
  353. {
  354.     long options;
  355.     Point tip;
  356.     Rect altRect;
  357.     short theProc;
  358.     short variant;
  359.     HMMessageRecord helpMessage;
  360. } HelpItemInfo;
  361.  
  362.     /*    High-level routines */
  363. #ifndef __PICKER__
  364. pascal Boolean GetColor(Point where,Str255 prompt,RGBColor *inColor,RGBColor *outColor);
  365. #endif
  366. pascal OSErr PickColor(ColorPickerInfo *theColorInfo);
  367.  
  368.     /* Low-level routines */
  369. pascal OSErr CreateColorDialog(SystemDialogInfo *info,picker *thePicker);
  370. pascal OSErr CreatePickerDialog(PickerDialogInfo *info,picker *thePicker);
  371. pascal OSErr AddPickerToDialog(ApplicationDialogInfo *info,picker *thePicker);
  372. pascal OSErr DisposeColorPicker(picker thePicker);
  373. pascal OSErr SetPickerVisibility(picker thePicker,short visible);
  374. pascal OSErr GetPickerVisibility(picker thePicker,Boolean *vis);
  375. pascal OSErr SetPickerPrompt(picker thePicker, Str255 promptString);
  376. pascal OSErr DoPickerEvent(picker thePicker,EventData *data);
  377. pascal OSErr DoPickerEdit(picker thePicker,EditData *data);
  378. pascal OSErr DoPickerDraw(picker thePicker);
  379. pascal OSErr GetPickerColor(picker thePicker,ColorType whichColor,PMColorPtr color);
  380. pascal OSErr SetPickerColor(picker thePicker,ColorType whichColor,PMColorPtr color);
  381. pascal OSErr SetPickerProfile(picker thePicker,CMProfileHandle profile);
  382. pascal OSErr GetPickerProfile(picker thePicker,CMProfileHandle *profile);
  383. pascal OSErr GetPickerOrigin(picker thePicker,Point *where);
  384. pascal OSErr SetPickerOrigin(picker thePicker,Point where);
  385. pascal OSErr GetPickerEditMenuState(picker thePicker,MenuState *mState);
  386. pascal OSErr ExtractPickerHelpItem(picker thePicker,short itemNo,short whichState,HelpItemInfo *helpInfo);
  387.  
  388.  
  389. #ifndef __PICKER__
  390.  
  391. /* stuff from the old Picker.h */
  392.  
  393. enum {MaxSmallFract = 0x0000FFFF};  /*Maximum small fract value, as long*/
  394.  
  395.  
  396. /* A SmallFract value is just the fractional part of a Fixed number,
  397. which is the low order word.  SmallFracts are used to save room,
  398. and to be compatible with Quickdraw's RGBColor.  They can be
  399. assigned directly to and from INTEGERs. */
  400.  
  401. typedef unsigned short SmallFract;    /* Unsigned fraction between 0 and 1 */
  402.  
  403. /* For developmental simplicity in switching between the HLS and HSV
  404. models, HLS is reordered into HSL.    Thus both models start with
  405. hue and saturation values; value/lightness/brightness is last. */
  406.  
  407.  
  408.  
  409. struct HSVColor {
  410.     SmallFract hue;                 /*Fraction of circle, red at 0*/
  411.     SmallFract saturation;            /*0-1, 0 for gray, 1 for pure color*/
  412.     SmallFract value;                /*0-1, 0 for black, 1 for max intensity*/
  413. };
  414.  
  415. typedef struct HSVColor HSVColor;
  416. /* For developmental simplicity in switching between the HLS and HSVmodels, HLS
  417.  is reordered into HSL.  Thus both models start with hue and saturation values;
  418.  value/lightness/brightness is last. */
  419. struct HSLColor {
  420.     SmallFract hue;                 /*Fraction of circle, red at 0*/
  421.     SmallFract saturation;            /*0-1, 0 for gray, 1 for pure color*/
  422.     SmallFract lightness;            /*0-1, 0 for black, 1 for white*/
  423. };
  424.  
  425. typedef struct HSLColor HSLColor;
  426.  
  427. struct CMYColor {
  428.     SmallFract cyan;
  429.     SmallFract magenta;
  430.     SmallFract yellow;
  431. };
  432.  
  433. typedef struct CMYColor CMYColor;
  434.  
  435. #endif
  436.  
  437. #ifdef __cplusplus
  438. extern "C" {
  439. #endif
  440.  
  441. #ifndef __PICKER__
  442. pascal SmallFract Fix2SmallFract(Fixed f)
  443.     = {0x3F3C,0x0001,0xA82E};
  444. pascal Fixed SmallFract2Fix(SmallFract s)
  445.     = {0x3F3C,0x0002,0xA82E};
  446. pascal void CMY2RGB(const CMYColor *cColor,RGBColor *rColor)
  447.     = {0x3F3C,0x0003,0xA82E};
  448. pascal void RGB2CMY(const RGBColor *rColor,CMYColor *cColor)
  449.     = {0x3F3C,0x0004,0xA82E};
  450. pascal void HSL2RGB(const HSLColor *hColor,RGBColor *rColor)
  451.     = {0x3F3C,0x0005,0xA82E};
  452. pascal void RGB2HSL(const RGBColor *rColor,HSLColor *hColor)
  453.     = {0x3F3C,0x0006,0xA82E};
  454. pascal void HSV2RGB(const HSVColor *hColor,RGBColor *rColor)
  455.     = {0x3F3C,0x0007,0xA82E};
  456. pascal void RGB2HSV(const RGBColor *rColor,HSVColor *hColor)
  457.     = {0x3F3C,0x0008,0xA82E};
  458. #endif
  459.  
  460. #ifndef RUN_LINKED_IN
  461. #ifndef __PICKER__
  462. pascal Boolean GetColor(Point where,Str255 prompt,RGBColor *inColor,RGBColor *outColor)
  463.     = {0x3F3C,0x0009,0xA82E};
  464. #endif
  465. pascal OSErr PickColor(ColorPickerInfo *theColorInfo)
  466.     = {0x3F3C,0x0213,0xA82E};
  467. pascal OSErr AddPickerToDialog(ApplicationDialogInfo *info,picker *thePicker)
  468.     = {0x3F3C,0x0414,0xA82E};
  469. pascal OSErr CreateColorDialog(SystemDialogInfo *info,picker *thePicker)
  470.     = {0x3F3C,0x0415,0xA82E};
  471. pascal OSErr CreatePickerDialog(PickerDialogInfo *info,picker *thePicker)
  472.     = {0x3F3C,0x0416,0xA82E};
  473. pascal OSErr DisposeColorPicker(picker thePicker)
  474.     = {0x3F3C,0x0217,0xA82E};
  475. pascal OSErr GetPickerVisibility(picker thePicker,Boolean *visible)
  476.     = {0x3F3C,0x0418,0xA82E};
  477. pascal OSErr SetPickerVisibility(picker thePicker,short visible)
  478.     = {0x3F3C,0x0319,0xA82E};
  479. pascal OSErr SetPickerPrompt(picker thePicker, Str255 promptString)
  480.     = {0x3F3C,0x041a,0xA82E};
  481. pascal OSErr DoPickerEvent(picker thePicker,EventData *data)
  482.     = {0x3F3C,0x041b,0xA82E};
  483. pascal OSErr DoPickerEdit(picker thePicker,EditData *data)
  484.     = {0x3F3C,0x041c,0xA82E};
  485. pascal OSErr DoPickerDraw(picker thePicker)
  486.     = {0x3F3C,0x021d,0xA82E};
  487. pascal OSErr GetPickerColor(picker thePicker,ColorType whichColor,PMColorPtr color)
  488.     = {0x3F3C,0x051e,0xA82E};
  489. pascal OSErr SetPickerColor(picker thePicker,ColorType whichColor,PMColorPtr color)
  490.     = {0x3F3C,0x051f,0xA82E};
  491. pascal OSErr GetPickerOrigin(picker thePicker,Point *where)
  492.     = {0x3F3C,0x0420,0xA82E};
  493. pascal OSErr SetPickerOrigin(picker thePicker,Point where)
  494.     = {0x3F3C,0x0421,0xA82E};
  495. pascal OSErr GetPickerProfile(picker thePicker,CMProfileHandle *profile)
  496.     = {0x3F3C,0x0422,0xA82E};
  497. pascal OSErr SetPickerProfile(picker thePicker,CMProfileHandle profile)
  498.     = {0x3F3C,0x0423,0xA82E};
  499. pascal OSErr GetPickerEditMenuState(picker thePicker,MenuState *mState)
  500.     = {0x3F3C,0x0424,0xA82E};
  501. pascal OSErr ExtractPickerHelpItem(picker thePicker,short itemNo,short whichState,HelpItemInfo *helpInfo)
  502.     = {0x3F3C,0x0625,0xA82E};
  503.  
  504. #endif
  505. #ifdef __cplusplus
  506. }
  507. #endif
  508.  
  509. #endif
  510.  
  511. #endif